// pages/message/index.js
// import {Dialog} from '@vant/weapp'
import Dialog from '@vant/weapp/dialog/dialog';
import {
  getChatListApi
} from '../../../https/chat'
import {
  BASE_URL
} from '../../../constant/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    BASE_URL,
    chatList: [],
    page: 1,
    limit: 20,
    total: 100
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getChatList()
  },
  onShow() {
    this.setData({
      chatList: [],
      page: 1,
      total: 100
    })
    this.getChatList()
  },
  // 获取聊天列表
  async getChatList() {
    const {
      page,
      limit,
      total
    } = this.data
    const getRes = await getChatListApi({
      page,
      limit,
      total
    })
    console.log(getRes)
    if (getRes.code == 200) {
      this.setData({
        page: getRes.data.page + 1,
        limit: getRes.data.limit,
        total: getRes.data.total,
        chatList: getRes.data.list,
      })
    }
  },
  // 关闭
  onClose(event) {
    const {
      position,
      instance
    } = event.detail;
    console.log(event)
    instance.close();
  },
  gotoChat(e) {
    console.log(e)
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../chat/index?docid=' + docid,
    })
  }

})